package view;

import model.PAppGrid;
import model.PAppRect;
import processing.core.*;

@SuppressWarnings("serial")
public class CanvasPApplet extends PApplet {
	private PAppGrid grid;
	private int height;
	private int width;
	private int sideSquares;
	
	public CanvasPApplet(int panelWidth, int panelHeight, int sideSquares) {
		height=panelHeight;
		width=panelWidth;		
		this.sideSquares=sideSquares;
		grid = new PAppGrid(sideSquares);
	}
	public void setup() {
	  size(width,height);
	  background(80);
	}
	public void draw() {
	  if(mousePressed){
	  	if(mouseButton==LEFT){
	  		grid.getSquareGrid()[sideSquares*mouseY/height][sideSquares*mouseX/width].setPath(true);
	  	}
	  	else if(mouseButton==RIGHT){
	  		grid.getSquareGrid()[sideSquares*mouseY/height][sideSquares*mouseX/width].setPath(false);
	  	}
	  }
	  for (PAppRect[] row:grid.getSquareGrid()) {
      //for each number in the row
      for (PAppRect rect : row) {
      	stroke(255);
  	  	fill(0);
  	  	if(rect.isPath()==true){
  	  	  stroke(0);
  	  		fill(255);
  	  	}
  	  	rect(rect.getPosX(), rect.getPosY(), rect.getSideLenghtX(), rect.getSideLenghtY());
      }
	  }
	}
	public PAppGrid getGrid() {
		return grid;
	}
	public void setGrid(PAppGrid grid) {
		this.grid = grid;
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public void resetGrid(){		
		for (PAppRect[] row:grid.getSquareGrid()) {
      //for each number in the row
      for (PAppRect rect : row) {
      	rect.setPath(false);
      }
	  }
	}
}
